from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel, Field


class RoleCreateDTO(BaseModel):
    """Role creation data transfer object."""
    name: str = Field(..., min_length=2, max_length=50)
    description: Optional[str] = None
    parent_role_id: Optional[UUID] = None


class RoleUpdateDTO(BaseModel):
    """Role update data transfer object."""
    name: Optional[str] = Field(None, min_length=2, max_length=50)
    description: Optional[str] = None
    parent_role_id: Optional[UUID] = None


class RoleDTO(BaseModel):
    """Role data transfer object."""
    id: UUID
    name: str
    description: Optional[str]
    parent_role_id: Optional[UUID]
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True
